package h2UDP;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

public class ReceiveDemo {
    public static void main(String[] args) throws IOException {
        //1创建接收端socket对象
        DatagramSocket ds=new DatagramSocket(10086);
        //2.创建接收端数据包，接收数据

        byte []bys=new byte[1024];

        DatagramPacket dp=new DatagramPacket(bys,bys.length);

        //调用接收
        ds.receive(dp);

        //解析数据包
        byte[] datas = dp.getData();
        int len=dp.getLength();
        String dataString =new String(datas,0,len);
        System.out.println("数据是："+dataString);

        //关闭接收端
        ds.close();


    }
}
